<!--
 
 Copyright (c) 2006 Michael Eddington
 
 Permission is hereby granted, free of charge, to any person obtaining a copy  
 of this software and associated documentation files (the "Software"), to deal 
 in the Software without restriction, including without limitation the rights  
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 copies of the Software, and to permit persons to whom the Software is  
 furnished to do so, subject to the following conditions: 
 
 The above copyright notice and this permission notice shall be included in  
 all copies or substantial portions of the Software. 
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
 SOFTWARE. 
 
 Authors:
   Michael Eddington (meddington@phed.org)

 $Id$
-->
<html>
<head>
<title>Test Page for Reform</title>
<script language="javascript" src="jsUnitCore.js"></script>
<script language="javascript" src="Reform.js"></script>
</head>
<body>
<script language="javascript">
	function testHtmlEncode()
	{
		// Non encoded characters
		assertEquals("Non encoding chars", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.",
			HtmlEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."));
		// Usual suspects
		assertEquals("Usual suspects", "&#60;&#62;&#38;&#34;",
			HtmlEncode("<>&\""));
		// Other characters
		assertEquals("Punctuation", "&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			HtmlEncode("`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
			
			assertEquals("Unicode characters to 6000 ["+i+"]", "&#" + i + ';',
				HtmlEncode(String.fromCharCode(i)));
		}
		
		assertEquals("Unicode characters to 6000", encodedStr,
			HtmlEncode(toEncode));
	}
	
	function testHtmlEncodeDefault()
	{
		// Usual stuff
		assertEquals("Checking default", "default", 
			HtmlEncode(null, "default"));
	
		// Non encoded characters
		assertEquals("Non encoding chars via default", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.",
			HtmlEncode(null, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."));
		// Usual suspects
		assertEquals("Usual suspects via default", "&#60;&#62;&#38;&#34;",
			HtmlEncode(null, "<>&\""));
		// Other characters
		assertEquals("Punctuation via default", "&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			HtmlEncode(null, "`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000 via default", encodedStr,
			HtmlEncode(null, toEncode));
		
		// The following are sanity checks
	
		// Non encoded characters
		assertEquals("Non encoding chars", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.",
			HtmlEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.", "default"));
		// Usual suspects
		assertEquals("Usual suspects", "&#60;&#62;&#38;&#34;",
			HtmlEncode("<>&\"", "default"));
		// Other characters
		assertEquals("Punctuation", "&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			HtmlEncode("`~!@#$%^&*()_+=-{}|\\][:;'/?><", "default"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000", encodedStr,
			HtmlEncode(toEncode, "default"));
	}
	
	function testHtmlAttributeEncode()
	{
		// Non encoded characters
		assertEquals("Non encoding chars", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321",
			HtmlAttributeEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321"));
		// Usual suspects
		assertEquals("Usual suspects", "&#60;&#62;&#38;&#34;",
			HtmlAttributeEncode("<>&\""));
		// Other characters
		assertEquals("Punctuation", "&#32;&#44;&#46;&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			HtmlAttributeEncode(" ,.`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000", encodedStr,
			HtmlAttributeEncode(toEncode));
	}
	
	function testHtmlAttributeEncodeDefault()
	{
		// Usual stuff
		assertEquals("Checking default", "default",
			HtmlAttributeEncode(null, "default"));
	
		// Non encoded characters
		assertEquals("Non encoding chars via default", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321",
			HtmlAttributeEncode(null, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321"));
		// Usual suspects
		assertEquals("Usual suspects via default", "&#60;&#62;&#38;&#34;",
			HtmlAttributeEncode(null, "<>&\""));
		// Other characters
		assertEquals("Punctuation via default", "&#32;&#44;&#46;&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			HtmlAttributeEncode(null, " ,.`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000 via default", encodedStr,
			HtmlAttributeEncode(null, toEncode));
	
		// The following are sanity checks
	
		// Non encoded characters
		assertEquals("Non encoding chars", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321",
			HtmlAttributeEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321", "default"));
		// Usual suspects
		assertEquals("Usual suspects", "&#60;&#62;&#38;&#34;",
			HtmlAttributeEncode("<>&\"", "default"));
		// Other characters
		assertEquals("Punctuation", "&#32;&#44;&#46;&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			HtmlAttributeEncode(" ,.`~!@#$%^&*()_+=-{}|\\][:;'/?><", "default"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000", encodedStr,
			HtmlAttributeEncode(toEncode, "default"));
	}

	function testXmlEncode()
	{
		// Non encoded characters
		assertEquals("Non encoding chars", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.",
			XmlEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."));
		// Usual suspects
		assertEquals("Usual suspects", "&#60;&#62;&#38;&#34;",
			XmlEncode("<>&\""));
		// Other characters
		assertEquals("Punctuation", "&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			XmlEncode("`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000", encodedStr,
			XmlEncode(toEncode));
	}
	
	function testXmlEncodeDefault()
	{
		assertEquals("Null for both parameters", "",
			XmlEncode(null, null));
		// Usual stuff
		assertEquals("Checking default", "default",
			XmlEncode(null, "default"));
	
		// Non encoded characters
		assertEquals("Non encoding chars via default", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.",
			XmlEncode(null, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."));
		// Usual suspects
		assertEquals("Usual suspects via default", "&#60;&#62;&#38;&#34;",
			XmlEncode(null, "<>&\""));
		// Other characters
		assertEquals("Punctuation via default", "&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			XmlEncode(null, "`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000 via default", encodedStr,
			XmlEncode(null, toEncode));
	
		// The following are sanity checks
	
		// Non encoded characters
		assertEquals("Non encoding chars", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.",
			XmlEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.", "default"));
		// Usual suspects
		assertEquals("Usual suspects", "&#60;&#62;&#38;&#34;",
			XmlEncode("<>&\"", "default"));
		// Other characters
		assertEquals("Punctuation", "&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			XmlEncode("`~!@#$%^&*()_+=-{}|\\][:;'/?><", "default"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000", encodedStr,
			XmlEncode(toEncode, "default"));
	}
	
	function testXmlAttributeEncode()
	{
		// Non encoded characters
		assertEquals("Non encoding chars", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321",
			XmlAttributeEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321"));
		// Usual suspects
		assertEquals("Usual suspects", "&#60;&#62;&#38;&#34;",
			XmlAttributeEncode("<>&\""));
		// Other characters
		assertEquals("Punctuation", "&#32;&#44;&#46;&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			XmlAttributeEncode(" ,.`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000", encodedStr,
			XmlAttributeEncode(toEncode));
	}
	
	function testXmlAttributeEncodeDefault()
	{
		assertEquals("Null for both parameters", "",
			XmlAttributeEncode(null, null));
		// Usual stuff
		assertEquals("Checking default", "default",
			XmlAttributeEncode(null, "default"));
	
		// Non encoded characters
		assertEquals("Non encoding chars via default", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321",
			XmlAttributeEncode(null, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321"));
		// Usual suspects
		assertEquals("Usual suspects via default", "&#60;&#62;&#38;&#34;",
			XmlAttributeEncode(null, "<>&\""));
		// Other characters
		assertEquals("Punctuation via default", "&#32;&#44;&#46;&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			XmlAttributeEncode(null, " ,.`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000 via default", encodedStr,
			XmlAttributeEncode(null, toEncode));
	
		// The following are sanity checks
	
		// Non encoded characters
		assertEquals("Non encoding chars", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321",
			XmlAttributeEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321", "default"));
		// Usual suspects
		assertEquals("Usual suspects", "&#60;&#62;&#38;&#34;",
			XmlAttributeEncode("<>&\"", "default"));
		// Other characters
		assertEquals("Punctuation", "&#32;&#44;&#46;&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
			XmlAttributeEncode(" ,.`~!@#$%^&*()_+=-{}|\\][:;'/?><", "default"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 127; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&#" + i + ';';
		}
		assertEquals("Unicode characters to 6000", encodedStr,
			XmlAttributeEncode(toEncode, "default"));
	}
	
	var hD="0123456789ABCDEF";
	function d2h(d)
	{
		var h = hD.substr(d&15,1);
		
		while( d > 15 )
		{
			d >>= 4;
			h = hD.substr(d & 15, 1) + h;
		}
		
		return h;
	}

	function bin2hex(i)
	{
		str = d2h(i);
		for(; str.length < 4; )
		{
			str = '0' + str;
		}
		return str;
		
	}
	
	function testJsString()
	{
		// Non encoded characters
		assertEquals("Non encoding chars", "'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.'",
			JsString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."));
		// Usual suspects
		assertEquals("Usual suspects", "'\\x3C\\x3E\\x26\\x22\\x5C\\x27'",
			JsString("<>&\"\\'"));
		// Other characters
		assertEquals("Punctuation", "'\\x60\\x7E\\x21\\x40\\x23\\x24\\x25\\x5E\\x26\\x2A\\x28\\x29\\x5F\\x2B\\x3D\\x2D\\x7B\\x7D\\x7C\\x5C\\x5D\\x5B\\x3A\\x3B\\x27\\x2F\\x3F\\x3E\\x3C'",
			JsString("`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		encodedStr += '\'';
		for (i = 128; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "\\u" + bin2hex(i);
		}
		encodedStr += '\'';
		assertEquals("Unicode characters to 6000", encodedStr,
			JsString(toEncode));
	}
	
	function testJsStringDefault()
	{
		assertEquals("Null for both parameters", "\'\'",
			JsString(null, null));
		// Usual stuff
		assertEquals("Checking default", "'default'",
			JsString(null, "default"));
	
		// Non encoded characters
		assertEquals("Non encoding chars via default", "'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.'",
			JsString(null, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."));
		// Usual suspects
		assertEquals("Usual suspects via default", "'\\x3C\\x3E\\x26\\x22\\x5C\\x27'",
			JsString(null, "<>&\"\\'"));
		// Other characters
		assertEquals("Punctuation via default", "'\\x60\\x7E\\x21\\x40\\x23\\x24\\x25\\x5E\\x26\\x2A\\x28\\x29\\x5F\\x2B\\x3D\\x2D\\x7B\\x7D\\x7C\\x5C\\x5D\\x5B\\x3A\\x3B\\x27\\x2F\\x3F\\x3E\\x3C'",
			JsString(null, "`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		encodedStr += '\'';
		for (i = 128; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "\\u" + bin2hex(i);
		}
		encodedStr += '\'';
		assertEquals("Unicode characters to 6000 via default", encodedStr,
			JsString(null, toEncode));
	
		// The following are sanity checks
	
		// Non encoded characters
		assertEquals("Non encoding chars", "'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.'",
			JsString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.", "default"));
		// Usual suspects
		assertEquals("Usual suspects", "'\\x3C\\x3E\\x26\\x22\\x5C\\x27'",
			JsString("<>&\"\\'", "default"));
		// Other characters
		assertEquals("Punctuation", "'\\x60\\x7E\\x21\\x40\\x23\\x24\\x25\\x5E\\x26\\x2A\\x28\\x29\\x5F\\x2B\\x3D\\x2D\\x7B\\x7D\\x7C\\x5C\\x5D\\x5B\\x3A\\x3B\\x27\\x2F\\x3F\\x3E\\x3C'",
			JsString("`~!@#$%^&*()_+=-{}|\\][:;'/?><", "default"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		encodedStr += '\'';
		for (i = 128; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "\\u" + bin2hex(i);
		}
		encodedStr += '\'';
		assertEquals("Unicode characters to 6000", encodedStr,
			JsString(toEncode, "default"));
	}

	function testVbsString()
	{
		assertEquals("\"abc\"&chrw(60)",
			VbsString("abc<"));
		assertEquals("chrw(60)&\"abc\"",
			VbsString("<abc"));
		// Non encoded characters
		assertEquals("Non encoding chars", "\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.\"",
			VbsString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."));
		// Usual suspects
		assertEquals("Usual suspects", "chrw(60)&chrw(62)&chrw(38)&chrw(34)&chrw(92)&chrw(39)",
			VbsString("<>&\"\\'"));
		// Other characters
		assertEquals("Punctuation", "chrw(96)&chrw(126)&chrw(33)&chrw(64)&chrw(35)&chrw(36)&chrw(37)&chrw(94)&chrw(38)&chrw(42)&chrw(40)&chrw(41)&chrw(95)&chrw(43)&chrw(61)&chrw(45)&chrw(123)&chrw(125)&chrw(124)&chrw(92)&chrw(93)&chrw(91)&chrw(58)&chrw(59)&chrw(39)&chrw(47)&chrw(63)&chrw(62)&chrw(60)",
			VbsString("`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 128; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&chrw("+i+")";
		}
		encodedStr = encodedStr.substr(1); // remove &
	
		assertEquals("Unicode characters to 6000", encodedStr,
			VbsString(toEncode));
	}
	
	function testVbsStringDefault()
	{
		assertEquals("Null for both parameters", "\"\"", 
			VbsString(null, null));
		assertEquals("\"abc\"&chrw(60)",
			VbsString(null, "abc<"));
		assertEquals("chrw(60)&\"abc\"",
			VbsString(null, "<abc"));
		// Usual stuff
		assertEquals("Checking default", "\"default\"",
			VbsString(null, "default"));
		
		// Non encoded characters
		assertEquals("Non encoding chars via default", "\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.\"",
			VbsString(null, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."));
		// Usual suspects
		assertEquals("Usual suspects via default", "chrw(60)&chrw(62)&chrw(38)&chrw(34)&chrw(92)&chrw(39)",
			VbsString(null, "<>&\"\\'"));
		// Other characters
		assertEquals("Punctuation via default", "chrw(96)&chrw(126)&chrw(33)&chrw(64)&chrw(35)&chrw(36)&chrw(37)&chrw(94)&chrw(38)&chrw(42)&chrw(40)&chrw(41)&chrw(95)&chrw(43)&chrw(61)&chrw(45)&chrw(123)&chrw(125)&chrw(124)&chrw(92)&chrw(93)&chrw(91)&chrw(58)&chrw(59)&chrw(39)&chrw(47)&chrw(63)&chrw(62)&chrw(60)",
			VbsString(null, "`~!@#$%^&*()_+=-{}|\\][:;'/?><"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 128; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&chrw("+i+")";
		}
		encodedStr = encodedStr.substr(1); // remove &
		assertEquals("Unicode characters to 6000 via default", encodedStr,
			VbsString(null, toEncode));
		
		// The following are sanity checks
		
		// Non encoded characters
		assertEquals("Non encoding chars", "\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.\"",
			VbsString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.", "default"));
		// Usual suspects
		assertEquals("Usual suspects", "chrw(60)&chrw(62)&chrw(38)&chrw(34)&chrw(92)&chrw(39)",
			VbsString("<>&\"\\'", "default"));
		// Other characters
		assertEquals("Punctuation", "chrw(96)&chrw(126)&chrw(33)&chrw(64)&chrw(35)&chrw(36)&chrw(37)&chrw(94)&chrw(38)&chrw(42)&chrw(40)&chrw(41)&chrw(95)&chrw(43)&chrw(61)&chrw(45)&chrw(123)&chrw(125)&chrw(124)&chrw(92)&chrw(93)&chrw(91)&chrw(58)&chrw(59)&chrw(39)&chrw(47)&chrw(63)&chrw(62)&chrw(60)",
			VbsString("`~!@#$%^&*()_+=-{}|\\][:;'/?><", "default"));
		// Unicode characters
		toEncode = '';
		encodedStr = '';
		for (i = 128; i < 6000; i++)
		{
			toEncode += String.fromCharCode(i);
			encodedStr += "&chrw("+i+")";
		}
		encodedStr = encodedStr.substr(1); // remove &
		assertEquals("Unicode characters to 6000", encodedStr,
			VbsString(toEncode, "default"));
	}

</script>
</body>
</html>
